package com.hema.auction.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.hema.auction.R;
import com.hema.auction.base.BaseActivity;
import com.hema.auction.bean.MessageInfo;
import com.hema.auction.http.HttpTag;
import com.hema.auction.http.biz.HttpManager;
import com.hema.auction.utils.Constant;
import com.hema.auction.utils.Utils;
import com.hema.auction.widget.view.TitleView;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;

/**
 * 消息详情
 * author by john
 */

public class MessageDescActivity extends BaseActivity {

    @BindView(R.id.title_view)
    TitleView titleView;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_desc)
    TextView tvDesc;
    @BindView(R.id.tv_from)
    TextView tvFrom;
    @BindView(R.id.tv_date)
    TextView tvDate;
    private MessageInfo info;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_desc);
        ButterKnife.bind(this);
        info = getIntent().getParcelableExtra(Constant.EXTRA_MESSAGE_INFO);
        titleView.setTitle(info.getTitle());
        tvTitle.setText(info.getTitle());
        tvDesc.setText(info.getContent());
        tvDate.setText(Utils.timedate(info.getAddtime()));
        HttpManager.getInstance(this).getNewCount(this);
    }

    @Override
    protected void onSuccess(HttpTag httpTag, Call call, JSONObject result) {
        super.onSuccess(httpTag, call, result);
        try {
            if (result.getInt("errcode") == 0) {
                spManager.setNewMessageCount(result.getJSONObject("data").getInt("msg_count"));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
